"""author: wenyao
   data: 2022/3/12
   project: pirate-king-2022
"""

# int 整型，表示范围无穷大
# print 输出函数
a = 1
print(a, "是", type(a), "类型")
a = -1
print(a, "是", type(a), "类型")
a = 2**100
print(a, "是", type(a), "类型")

# 进制 print进行输出的时候，默认情况用十进制方式输出
# 二进制（0、1）
a = 0b10101
print(a, "是", type(a), "类型")

# 十六进制（0-9，a-f）
a = 0x1fb
print(a, "是", type(a), "类型")

# 八进制 (0-7)
a = 0o172
print(a, "是", type(a), "类型")

# 进制转换 bin, oct, hex
help(bin)
# bin(number) => 二进制字符串
a = 10
print(a,"转换成二进制的结果是", bin(a))
a = 0x10
print(a,"转换成二进制的结果是", bin(a))
# 自己测试一下

help(hex)
# hex(number) => 十六进制字符串
a = 10
print(a,"转换成十六进制的结果是", hex(a))
a = 0x10
print(a,"转换成十六进制的结果是", hex(a))
# help(oct)
# hex(number) => 八进制字符串

a = 10
# a_oct => 字符串 => 八进制字符串
a_oct = oct(a)
print(a_oct)

# int的参数是一个字符串，指定base(给的参数是几进制数据，默认base是10)
a_int = int(a_oct, base=8)
print("结果是", a_int)
a_int = int('111')
a_int = int('111', base=10)
print("结果是", a_int)

# 传递一个进制参数
a_int = int('1010', base=2)
print("结果是", a_int)
a_int = int('0b1010', base=2)
print("结果是", a_int)


# help(int)
print(int(0b1001))

#
# num1 = input("num1=")
# num2 = input("num2=")
# sum = int(num1)+int(num2)
# print("num1+num2=",sum)
#






b = 1.1
print(b,"的数据类型是" ,type(b))
b = 1.
print(b,"的数据类型是" ,type(b))
b = 4.2E-10
print(b,"的数据类型是" ,type(b))



## float数据是不精确的
i = 1
i = i-0.1
print(i)
i = i-0.1
print(i)
i = i-0.1
print(i)
i = i-0.1
print(i)

"""
十进制5表示为101
5 => 101 => 1*2**0+0*2**1+1*2**2
0.1 =>  0.5 , 0.25, 0.125, 0.0625  
    =>  部分小数是无用二进制精确地表示出来
    => 0b0.1 => 0.5 

条件判断 如果用浮点型数据变量尽量要使用<或>来进行比较 
避免使用等于来比较 a == 0.6
"""

# Decimal 可以表示精确的浮点数
# 2.1 => 整数位和小数分别存储 => 使用整数的存储方式来存储的
# 2 => 10
# 1 => 1

from decimal import Decimal
# Decimal数据类型
my_dec = Decimal('0.1') # 表示精确的0.1数据
print(my_dec, type(my_dec))
my_dec = Decimal(0.1)
print(my_dec, type(my_dec))
my_dec = Decimal(0.5)
print(my_dec, type(my_dec))




c = 1+1j
print(c, type(c))
d = 4-2j
print(c+d)